﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Eksponent.CropUp.Client;
using Umbraco.Core;
using Umbraco.Web;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.web;
using System.Threading;

namespace Eksponent.CropUp.Umbraco
{
    public class UmbracoDefaults : IApplicationEventHandler
    {
        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(RegisterResourceUrls));
        }

        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {

        }

        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {

        }

        private void RegisterResourceUrls(object state)
        {
            var p = new Page();
            CropUpHtml.CropUpScript = p.ClientScript.GetWebResourceUrl(typeof(Cropper), "Eksponent.CropUp.Umbraco.Resources.CropUp.js");
            CropUpHtml.CropUpEditorScript = p.ClientScript.GetWebResourceUrl(typeof(Cropper), "Eksponent.CropUp.Umbraco.Resources.CropUp.Editor.js");
        }

    }
}
